package com.hf.security

import org.apache.commons.lang.RandomStringUtils

class ValidCodeService {

	ValidCode getValidCode(String email) {

		String code = RandomStringUtils.randomAlphanumeric(10)
		ValidCode validCode = ValidCode.findByEmail(email)
		if (validCode == null) {
			validCode = new ValidCode(email : email, code : code)
		} else {
			validCode.code = code
		}
		validCode.save()

		return validCode
	}
}
